package com.neusoft.elmboot.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.elmboot.po.Business;
import com.neusoft.elmboot.po.Food;
import com.neusoft.elmboot.po.User;
import com.neusoft.elmboot.service.BusinessService;

@RestController
@RequestMapping("/businesses")
@Validated
public class BusinessController {

	@Autowired
	private BusinessService businessService;

	//@RequestMapping("/listBusinessByOrderTypeId")
	@GetMapping("/orderType/{orderTypeId}")
	public List<Business> listBusinessByOrderTypeId(@PathVariable Integer orderTypeId) throws Exception{
		if(orderTypeId == 0) {
			return businessService.getAllBusinesses();
		}
		else {
		return businessService.listBusinessByOrderTypeId(orderTypeId);
		}
	}
	
	//@RequestMapping("/getBusinessById")
	@GetMapping("/{businessId}")
	public Business getBusinessById(@PathVariable Integer businessId) throws Exception{
		return businessService.getBusinessById(businessId);
	}
	
	 @GetMapping("/search")
	    public List<Business> searchBusiness(@RequestParam String keyword) {
	        return businessService.searchBusiness(keyword);
	    }
	
	//GetUserBySellerIdByUserId
	@PostMapping("/login")
	public Business getUserBySIdByUId(@RequestBody Business business) throws Exception{
		return businessService.getUserBySIdByUId(business);
	}
	
	//GetBySellerId
	@GetMapping("/sellerId/{sellerId}")
	public Business getBusinessBySId(@PathVariable Integer sellerId) throws Exception{
		return businessService.getBusinessBySId(sellerId);
	}
	
	//注册商家
	@PostMapping
	public Integer registerBusiness(@RequestBody Business business) {
		return businessService.registerBusiness(business);
	}
	//更新商家信息
	@PutMapping
	public Integer updateBusiness(@RequestBody Business business) {
		return businessService.updateBusiness(business);
	}
	//删除商家信息
	@DeleteMapping("/{businessId}")
	public Integer deleteBusiness(@PathVariable Integer businessId) {
		return businessService.deleteBusiness(businessId);
	}

}